package com.aischool.webapp.family;

import com.aischool.params.AiArticleParams;
import com.aischool.params.AiCourseParams;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiAppArticleService;
import com.aischool.service.AiArticleService;
import com.aischool.service.AiArticlecatService;
import com.aischool.service.AiCourseService;
import com.aischool.utils.AppUtil;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;

@RouteMapping(url = "/front/family/nurture")
public class NurtureController extends BaseFamilyController {


	@Inject
	AiArticleService aiArticleService;
	@Inject
	AiArticlecatService aiArticlecatService;
	@Inject
	AiAppArticleService aiAppArticleService;
	@Inject
	AiCourseService aiCourseService;
	
	public void index() {
		render(view_path + "/nurture.html");
	}
	
	public void getPage() {
		// 结果类
		JsonResult jr = new JsonResult();
		// 参数类
		AiArticleParams params = new AiArticleParams();
		
		// 获取参数
		int org_id = this.getAttrForInt("login_org_id");
		
		int link_course = getInt("link_course", 0);
		
		params.setPageNo(getParaToInt("pageNo", 1));
		params.setPageSize(getParaToInt("pageSize", AppUtil.Default_PageSize));
		
		params.setState(1);
		params.setUseState(getParaToInt("usestate", -1));
		
		params.setOrgId(org_id);
		params.setCatId(getInt("catid",0));
		params.setTypeId(getInt("typeid",0));
		
		if (params.getPageNo() == 1 && params.getCatId() == 0) {
			Object obj = aiArticlecatService.getOrgCat(org_id, params.getTypeId(), 1);
			if (obj != null) { jr.setDicKV("listcat", obj); }
		}
		
		if (link_course == -100 || link_course == 0) {
			// 获取分页
			Object pageData = aiArticleService.getPage(params);
			jr.setDicKV("pageData", pageData);
		}
		if (link_course == -100 || link_course == 1) {
			AiCourseParams params1 = new AiCourseParams();
			params1.setPageNo(getParaToInt("pageNo", 1));
			params1.setPageSize(getParaToInt("pageSize", AppUtil.Default_PageSize));
			
			params1.setState(1);
			
			params1.setOrgId(org_id);
			params1.setArticle_Catid(getInt("catid",0));
			params1.setPoid(3);
			
			Object pageData = aiCourseService.getPage(params1);
			jr.setDicKV("pageCourses", pageData);
		}
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	public void article() {
		int id = getInt("id", 0);
		Record rd = aiArticleService.getOne(id);
		this.setAttr("article_rd", rd);
		render(view_path + "/article.html");
	}
}
